import java.util.*;
import javafx.util.Pair;
public class Main {
    static int n;
    static int[][] arr;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        arr = new int[n][2];
        for (int i = 0; i < n; i++) {
            arr[i][0] = sc.nextInt();
            arr[i][1] = sc.nextInt();
        }
        //按照第一个关键字排序
        //Arrays.sort(arr,(a,b)->Integer.compare(a[0],b[0]));
        //另一种写法
        //Arrays.sort(arr, Comparator.comparingInt(a -> a[0]));
        //按照双关键字排序
        Arrays.sort(arr,(a,b)->{
           if(a[0]==b[0])return Integer.compare(a[1],b[1]);
           else return Integer.compare(a[0],b[0]);
        });
//        for(int i = 0; i < n; i++){
//            System.out.println(arr[i][0]+" "+arr[i][1]);
//        }
        ArrayList<Pair<Integer,Integer>>res = new ArrayList<>();
        int begin = arr[0][0], end = arr[0][1];
        for(int i = 1; i < n; i++){
            if(arr[i][0]>end){
                Pair<Integer,Integer> pair = new Pair<>(begin,end);
                res.add(pair);
                begin = arr[i][0];
                end = arr[i][1];
            }
            else{
                end = Math.max(end,arr[i][1]);
            }
        }
        Pair<Integer,Integer> pair = new Pair<>(begin,end);
        res.add(pair);

        System.out.println(res.size());
    }
}